package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// UpgradeVersion 升级版本
type UpgradeVersion struct {
	ID           string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	Version      string `json:"version" gorm:"column:version;type:string;size:50;index:version,unique,priority:1;comment:版本"`
	TerminalType string `json:"terminal_type" gorm:"column:terminal_type;type:string;size:64;index:version,unique,priority:2;comment:终端类型"`
	ChangeLog    string `json:"change_log" gorm:"column:change_log;type:text;comment:更新日志"`
	CreatedAt    int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt    int64  `json:"updated_at" gorm:"column:updated_at;autoUpdateTime:false;type:int;size:64;comment:更新时间"`
}

// TableName 表名
func (UpgradeVersion) TableName() string {
	return "upgrade_version"
}

// BeforeCreate 自增id
func (u *UpgradeVersion) BeforeCreate(tx *gorm.DB) (err error) {
	if u.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	u.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &UpgradeVersion{})
}
